﻿Global.namespace("System.Core.UI");
System.Core.UI.Repeater=function(config){
    System.Core.UI.Repeater.superclass.contructor.call(this,config);
};
System.Core.UI.Repeater=Global.extend(System.Core.UI.BaseControl,{
   dataStore:[],
   headerTemplate:function(){ return "<ul>";},
   itemTemplate:function(item){ return "<li>Data row</li>";},
   noItemTemplate:function(){ return "No data was found"; },
   footerTemplate:function(item){ return "</ul>"; },
   load:function(){
        try{
            var ctr=this;
            // create header template
            var html=this.headerTemplate();
            if(this.isObjectDataStore && this.dataStore){
                this.dataStore.each(function(item){
                    html+=ctr.itemTemplate(item);
                });
            }else if( this.dataStore.length>0){
                // create template for each item in data store
                for(var index=0;index<this.dataStore.length;index++){
                    html+=this.itemTemplate(this.dataStore[index]);
                }
            }else{
                // create tmplate in case of no data was bound
                html+=this.noItemTemplate();
            }
            // footer template
            html+=this.footerTemplate();
            // set it  as innerHtml of control
            this.innerHtml=html;
        }catch(e){
            e.source="Repeater.load function";
            ExceptionHandler.throwEx(e);
        }
   }
});